home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!news1!news
- From: pbennett@acraline.com (Patrick Bennett)
- Subject: Re: Multithreading with BC4.5
- X-Nntp-Posting-Host: machine131.acraline.com
- Message-ID: <310f8e18.2686784@news.iquest.net>
- Sender: news@iquest.net (News Admin)
- Reply-To: pbennett@acraline.com
- Organization: Acraline Products
- X-Newsreader: Forte Agent .99c/16.141
- References: <4ejl6d$1ck@news00.btx.dtag.de>
- Date: Wed, 31 Jan 1996 15:48:14 GMT
-
- PHoersemann@t-online.de (Peter Hrsemann) wrote:
-
- >Hello Folks !
- >
- >This is my first posting to a newsgroup and I hope to get plenty of
- >feedback :-)
-
- Good or bad feedback - there's plenty of it here! Regrettably, more
- often than not, there's quite a bit more of the latter.
- >
- >My problem:
- >I want to call a member function of an existing object as a background
- >thread. Therefore I created a friend function in its class :
- >
- >void friendfunc(void* obj)
- >
- >, which is called by:
- >
- >_beginthread(friendfunc,4096,(void*)obj);
- >
- >In this friend function, I want to call a member function of obj.
- >Because of its actual type void*, I have to do a type conversion.
- >But how ?? What is the correct type conversion, so I am able to call
- >obj.memberfunc ?
- >Is there a complete different (better?) way to solve the whole problem
- >?
-
- The function address you provide to _beginthread will need to be to a
- 'static' function within a class (if you want it to be within a
- class). You might want to take a look at the C++ FAQ. I believe it
- covers why this is so.
-
- As for threads in Borland, you might want to take a look at the
- TThread class that comes with Borland. It makes using threads pretty
- darn easy. All you have to do is derive a class of yours from TThread
- and provide a 'Run' method. The run method is what gets spawned as a
- separate thread when you Start() the thread. Your run method can then
- periodically check the ShouldTerminate() status to determine when/if
- it should exit. For simple uses, I usually put a call to Start() in
- the constructor of the class, and a call to Terminate() (which sets
- the 'Terminate' flag) in the destructor.
-
- One thing though which bit me BIG TIME. You need to do a compile in
- the bc45\source\classlib directory (look at the makefile) of the
- classlib's with MULTITHREADING turned on (-DMT). Otherwise, the
- default classlib's use 'CreateThread' instead of _beginthreadNT which
- caused me an endless amount of heartache. My programs worked and the
- threads worked, but as soon as I threw an exception in a thread - WHAM
- - it was toast. Because the lib's used CreateThread instead of
- _beginthreadNT the thread wasn't setup properly for the RTL.
-
-
- -------------------------------------------
- Patrick Bennett
- Acraline Products, Inc.
- pbennett@acraline.com / CIS: 74103,2115
-